package com.example.lotterysystem.common.exception;

import com.example.lotterysystem.common.Result;
import com.example.lotterysystem.common.enums.GlobalErrorCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public <T> Result<T> exception(GlobalException e){
        log.error("globalException {},", e.getMessage() + ": " +  e.getErrorCause(), e);
        return Result.error(GlobalErrorCodeEnum.SYSTEM_ERROR.getCode(), e.getMessage() + ": " + e.getErrorCause());
    }
    @ExceptionHandler
    public <T> Result<T> exception(Exception e){
        log.error("globalException ", e);
        return Result.error(GlobalErrorCodeEnum.UNKNOWN.getCode(), GlobalErrorCodeEnum.UNKNOWN.getMsg() + ": " + e.getMessage());
    }
}
